package com.googlecode.FWT.view.pages.introduction
{
	import com.googlecode.FWT.core.NotificationNames;
	
	import flash.events.Event;
	
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	/**
	* 
	*/
	public class IntroductionPageMediator extends Mediator
	{
		/**
		 * 
		 */
		public static const NAME:String = "IntroductionPageMediator";
		/**
		 * Constructor. 
		 * @param viewComponent
		 * 
		 */
		public function IntroductionPageMediator(viewComponent:IntroductionPage)
		{
			super(NAME, viewComponent);
		}
		/**
		 * Add event listener to detect changes to the name and essay title fields. 
		 * 
		 */
		override public function onRegister():void
		{		
			viewRef.addEventListener(IntroductionPage.NAME, onNameChanged);
			viewRef.addEventListener(IntroductionPage.TITLE, onTitleChanged);
		}
		/**
		 * Clean up on removal of mediator. 
		 * 
		 */
		override public function onRemove():void
		{
			viewRef.removeEventListener(IntroductionPage.NAME, onNameChanged);
			viewRef.removeEventListener(IntroductionPage.TITLE, onTitleChanged);
		}
		/**
		 * Respond to changes within the name field. 
		 * @param evt
		 * 
		 */
		protected function onNameChanged(evt:Event):void
		{
			sendNotification(NotificationNames.NAME_FIELD, viewRef.userName.text);
		}
		/**
		 * Respond to changes within the title field.
		 * @param evt
		 * 
		 */
		protected function onTitleChanged(evt:Event):void
		{
			sendNotification(NotificationNames.TITLE_FIELD, viewRef.essayTitle.text);
		}
		/**
		 * Returns a correctly typed reference to the view component. 
		 * @return 
		 * 
		 */
		protected function get viewRef():IntroductionPage
		{
			return viewComponent as IntroductionPage;
		}
	}
}